스타일 텍스트 추가
IronWord 의 "텍스트 스타일 추가" 기능은 개발자가 DOCX 문서에 콘텐츠를 추가하는 동안 다양한 텍스트 스타일 옵션을 적용할 수 있도록 합니다. 글꼴 종류, 크기, 색상, 굵게, 기울임, 밑줄, 취소선과 같은 스타일 속성을 지정하는 등 텍스트의 모양을 세밀하게 제어할 수 있습니다. 개발자는 Run 객체를 생성하여 TextContent를 포함시키고, TextStyle를 Run에게 할당하여 문서 내 개별 텍스트 요소의 표현을 맞춤 설정할 수 있으며, 사용자 정의된 룩앤필을 보장할 수 있습니다.
이 기능은 보고서나 편지처럼 특정 섹션에 서로 다른 스타일이 필요한 전문적인 형식의 문서를 동적으로 생성하는 데 유용합니다. TextStyle 클래스는 이러한 속성의 쉬운 조작을 가능하게 하며, 동일한 문서 내에서 단순하거나 복잡한 스타일링을 허용합니다.
핵심 사항
-
스타일이 적용된 실행 화면 만들기 :
- A
Runobject is created containingTextContentwith the desired text. - The
Styleproperty of theRunis assigned aTextStyleobject to apply formatting.
- A
-
텍스트 스타일 구성 :
FontSize: Set at theTextStylelevel (not insideFont) to specify text size.TextFont: Contains font properties includingFontFamilyfor font selection.Color: Specifies the text color usingIronWord.Models.Color.IsBoldandIsItalic: Boolean properties for bold and italic formatting.Underline: Adds underline styling to the text.Strike: Applies strikethrough formatting usingStrikeValueenum.
- 문서에 추가하기 :
- Use
AddChildto add the styledRunto aParagraph. - The paragraph is then added to the document with
AddParagraph.
- Use
코드 설명
이 코드는 IronWord 사용하여 DOCX 문서에 텍스트를 생성하고 스타일을 지정하는 방법을 보여줍니다. It begins by initializing a new WordDocument object, representing the document to be generated. A Run object is created containing TextContent with the string "Styled text example" and a TextStyle is applied to the Run to configure the appearance of the text.
The TextStyle includes settings for font size set at the TextStyle level (not inside Font), font family configured via TextFont, text color, and bold formatting. 이 설정은 최종 문서에서 텍스트가 표시되는 방식을 사용자 지정합니다.
After the Run is styled, the AddChild method adds the Run object to a paragraph in the document. 이 방법은 스타일이 적용된 콘텐츠를 적절한 형식으로 워드 문서에 삽입합니다. Finally, the SaveAs method is called to export the document as "styled_document.docx". 결과적으로 삽입된 텍스트가 지정된 스타일에 따라 서식이 지정되고 모든 글꼴 및 서식 속성이 출력 파일에 유지되는 Word 문서가 생성됩니다.

